from utils.xpath_utils import get_alltext_exclude_table,get_table_text
from scrapy.selector import Selector
from project_setting import PROJECT_ROOT
import os

def test_get_table_text():
    test_html_path = os.path.join(PROJECT_ROOT, "test/table_demo_html/xpath_utils_test_1.html")
    with open(test_html_path, encoding='utf-8') as fread:
        sel = Selector(text=fread.read())
    table_nodes = sel.xpath('//table')
    for table in table_nodes:
        print(get_table_text(table))
        print("end")

def test_getalltext_exclude_table():
    test_html_path = os.path.join(PROJECT_ROOT, "test/table_demo_html/xpath_utils_test_1.html")
    with open(test_html_path, encoding='utf-8') as fread:
        sel = Selector(text=fread.read())
    body_node = sel.xpath('//body')

    print(get_alltext_exclude_table(body_node))

if __name__ == '__main__':
    test_get_table_text()